{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "6985c023",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(1, 2, 3, 4, 5, 6)"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "it =range(1,7)\n",
    "tpl = tuple(it)\n",
    "tpl"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "45e0858b",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "tpl[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "27ada67c",
   "metadata": {},
   "outputs": [
    {
     "ename": "IndexError",
     "evalue": "tuple index out of range",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mIndexError\u001b[0m                                Traceback (most recent call last)",
      "Input \u001b[1;32mIn [5]\u001b[0m, in \u001b[0;36m<cell line: 1>\u001b[1;34m()\u001b[0m\n\u001b[1;32m----> 1\u001b[0m \u001b[43mtpl\u001b[49m\u001b[43m[\u001b[49m\u001b[38;5;241;43m8\u001b[39;49m\u001b[43m]\u001b[49m\n",
      "\u001b[1;31mIndexError\u001b[0m: tuple index out of range"
     ]
    }
   ],
   "source": [
    "tpl[8]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "b5dc0638",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(3, 4, 5)"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "tpl[2:5]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "1a7f7e59",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(1, 2, 3, 4, 5, 6, 7, 8)"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "tpl2=(7,8)\n",
    "tpl3=tpl+tpl2\n",
    "tpl3"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "6c8c4e5f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "3056198841920"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "id(tpl)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "1ad8453d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[1, 2, 3, 4, 5, 6, 7, 8]"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "lst=list(tpl3)\n",
    "lst"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "e54bb702",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "4"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "lst[3]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "8c1d0984",
   "metadata": {},
   "outputs": [],
   "source": [
    "lst[3]=66"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "cf7df09b",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[1, 2, 3, 66, 5, 6, 7, 8]"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "lst"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "1692af1e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(1, 2, 3, 4, 5, 6, 7, 8)"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "tpl3"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "57acb23a",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[('A', 47), ('B', 73), ('C', 67), ('D', 89), ('E', 89), ('F', 62), ('G', 64), ('H', 70), ('I', 75), ('J', 44)]\n",
      "平均分： 68.0\n",
      "不及格人数： 2\n"
     ]
    }
   ],
   "source": [
    "import random\n",
    "stu=[]\n",
    "for c in 'ABCDEFGHIJ':\n",
    "    fs = (c,random.randint(40,100))\n",
    "    stu.append(fs)\n",
    "    \n",
    "print(stu)\n",
    "score = sum([s[1] for s in stu])\n",
    "print('平均分：',score / len(stu))\n",
    "stu2 = [s for s in stu if s[1]<60]\n",
    "print('不及格人数：',len(stu2))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "168b4f5e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "680"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "score"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "5160a584",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "73"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "stu[1][1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "0fe806e0",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "67"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "stu[2][1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "dc5a726e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "('B', 73)"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "stu[1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "bed4ec30",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[('A', 47),\n",
       " ('B', 73),\n",
       " ('C', 67),\n",
       " ('D', 89),\n",
       " ('E', 89),\n",
       " ('F', 62),\n",
       " ('G', 64),\n",
       " ('H', 70),\n",
       " ('I', 75),\n",
       " ('J', 44)]"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "stu"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "bf6151e5",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[('A', 47), ('J', 44)]"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "stu2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "06d6c481",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
